using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSGPP.func;
namespace TVSBH.func
{
	public class frmBookSellNotBill : Form
	{
		private IContainer components = null;
		private DataGridView dgvProduct;
		private Button btnClose;
		private Button btnPrint;
		private Button btnExportToExcel;
		private GroupBox groupBox1;
		private Button btnSearch;
		private System.Windows.Forms.Label label25;
		private System.Windows.Forms.Label label17;
		private DateTimePicker dtpTo;
		private DateTimePicker dtpFrom;
		private DataGridViewTextBoxColumn createDate;
		private DataGridViewTextBoxColumn Address;
		private DataGridViewTextBoxColumn Diagnosis;
		private DataGridViewTextBoxColumn DrugsUsed;
		private DataGridViewTextBoxColumn DateStart;
		private DataGridViewTextBoxColumn _DoctorDesease;
		private DataGridViewTextBoxColumn Note;
		private DataGridViewTextBoxColumn ID;
		private Func objFunc = new Func();
		private DataTable objTable;
		private DataTable objTableBarcode = new DataTable();
		private Bill objBill = new Bill();
		private string sqlCon = "";
		private string currWhID = "";
		public string userName = "";
		public string fullName = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle7 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle8 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmBookSellNotBill));
			this.dgvProduct = new DataGridView();
			this.createDate = new DataGridViewTextBoxColumn();
			this.Address = new DataGridViewTextBoxColumn();
			this.Diagnosis = new DataGridViewTextBoxColumn();
			this.DrugsUsed = new DataGridViewTextBoxColumn();
			this.DateStart = new DataGridViewTextBoxColumn();
			this._DoctorDesease = new DataGridViewTextBoxColumn();
			this.Note = new DataGridViewTextBoxColumn();
			this.ID = new DataGridViewTextBoxColumn();
			this.btnClose = new Button();
			this.btnPrint = new Button();
			this.btnExportToExcel = new Button();
			this.groupBox1 = new GroupBox();
			this.btnSearch = new Button();
			this.label25 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.dtpTo = new DateTimePicker();
			this.dtpFrom = new DateTimePicker();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.createDate,
				this.Address,
				this.Diagnosis,
				this.DrugsUsed,
				this.DateStart,
				this._DoctorDesease,
				this.Note,
				this.ID
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 64);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(886, 498);
			this.dgvProduct.TabIndex = 1;
			this.createDate.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.createDate.DataPropertyName = "createDate";
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle2.Format = "D";
			dataGridViewCellStyle2.NullValue = null;
			this.createDate.DefaultCellStyle = dataGridViewCellStyle2;
			this.createDate.HeaderText = "Ngày";
			this.createDate.MinimumWidth = 80;
			this.createDate.Name = "createDate";
			this.createDate.ReadOnly = true;
			this.createDate.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.createDate.Width = 80;
			this.Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Address.DataPropertyName = "productName";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
			this.Address.DefaultCellStyle = dataGridViewCellStyle3;
			this.Address.HeaderText = "Tên thuốc";
			this.Address.MinimumWidth = 200;
			this.Address.Name = "Address";
			this.Address.ReadOnly = true;
			this.Address.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Address.Width = 200;
			this.Diagnosis.DataPropertyName = "productUnit";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle4.ForeColor = Color.Black;
			this.Diagnosis.DefaultCellStyle = dataGridViewCellStyle4;
			this.Diagnosis.HeaderText = "Đơn vị tính";
			this.Diagnosis.MinimumWidth = 120;
			this.Diagnosis.Name = "Diagnosis";
			this.Diagnosis.ReadOnly = true;
			this.Diagnosis.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Diagnosis.Width = 120;
			this.DrugsUsed.DataPropertyName = "productNumber";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle5.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle5.ForeColor = Color.Black;
			dataGridViewCellStyle5.Format = "N0";
			dataGridViewCellStyle5.NullValue = null;
			this.DrugsUsed.DefaultCellStyle = dataGridViewCellStyle5;
			this.DrugsUsed.HeaderText = "Sl Mua";
			this.DrugsUsed.MinimumWidth = 80;
			this.DrugsUsed.Name = "DrugsUsed";
			this.DrugsUsed.ReadOnly = true;
			this.DrugsUsed.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.DrugsUsed.Width = 80;
			this.DateStart.DataPropertyName = "productNumber";
			dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle6.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle6.ForeColor = Color.Black;
			dataGridViewCellStyle6.Format = "N0";
			dataGridViewCellStyle6.NullValue = null;
			this.DateStart.DefaultCellStyle = dataGridViewCellStyle6;
			this.DateStart.HeaderText = "Sl Bán";
			this.DateStart.MinimumWidth = 80;
			this.DateStart.Name = "DateStart";
			this.DateStart.ReadOnly = true;
			this.DateStart.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.DateStart.Width = 80;
			this._DoctorDesease.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this._DoctorDesease.DataPropertyName = "_DoctorDesease";
			dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle7.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			dataGridViewCellStyle7.ForeColor = Color.Black;
			this._DoctorDesease.DefaultCellStyle = dataGridViewCellStyle7;
			this._DoctorDesease.HeaderText = "Mục đích điều trị";
			this._DoctorDesease.MinimumWidth = 200;
			this._DoctorDesease.Name = "_DoctorDesease";
			this._DoctorDesease.ReadOnly = true;
			this._DoctorDesease.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Note.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Note.DataPropertyName = "Note";
			dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleLeft;
			this.Note.DefaultCellStyle = dataGridViewCellStyle8;
			this.Note.HeaderText = "Diễn giải";
			this.Note.MinimumWidth = 120;
			this.Note.Name = "Note";
			this.Note.ReadOnly = true;
			this.Note.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ID.DataPropertyName = "Pid";
			this.ID.HeaderText = "Column1";
			this.ID.Name = "ID";
			this.ID.ReadOnly = true;
			this.ID.Visible = false;
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(793, 568);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(100, 26);
			this.btnClose.TabIndex = 38;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new System.Drawing.Point(7, 568);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(107, 26);
			this.btnPrint.TabIndex = 66;
			this.btnPrint.Text = "In báo cáo [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnUpdate_Click);
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new System.Drawing.Point(117, 568);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(102, 26);
			this.btnExportToExcel.TabIndex = 67;
			this.btnExportToExcel.Text = "Xuất file Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.BackColor = Color.White;
			this.groupBox1.Controls.Add(this.btnSearch);
			this.groupBox1.Controls.Add(this.label25);
			this.groupBox1.Controls.Add(this.label17);
			this.groupBox1.Controls.Add(this.dtpTo);
			this.groupBox1.Controls.Add(this.dtpFrom);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new System.Drawing.Point(7, 6);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(886, 54);
			this.groupBox1.TabIndex = 68;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thời gian xem sổ";
			this.btnSearch.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSearch.FlatStyle = FlatStyle.Flat;
			this.btnSearch.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
//			this.btnSearch.Image = (Image)componentResourceManager.GetObject("btnSearch.Image");
			this.btnSearch.Location = new System.Drawing.Point(366, 21);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new Size(21, 21);
			this.btnSearch.TabIndex = 152;
			this.btnSearch.UseVisualStyleBackColor = true;
			this.btnSearch.Click += new EventHandler(this.btnSearch_Click);
			this.label25.AutoSize = true;
			this.label25.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label25.Location = new System.Drawing.Point(113, 24);
			this.label25.Name = "label25";
			this.label25.Size = new Size(57, 15);
			this.label25.TabIndex = 151;
			this.label25.Text = "Từ ngày :";
			this.label17.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
//			this.label17.Image = (Image)componentResourceManager.GetObject("label17.Image");
			this.label17.Location = new System.Drawing.Point(258, 20);
			this.label17.Name = "label17";
			this.label17.Size = new Size(20, 25);
			this.label17.TabIndex = 150;
			this.dtpTo.CustomFormat = "dd/MM/yyyy";
			this.dtpTo.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpTo.Format = DateTimePickerFormat.Custom;
			this.dtpTo.Location = new System.Drawing.Point(280, 21);
			this.dtpTo.Name = "dtpTo";
			this.dtpTo.Size = new Size(81, 21);
			this.dtpTo.TabIndex = 149;
			this.dtpFrom.CustomFormat = "dd/MM/yyyy";
			this.dtpFrom.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpFrom.Format = DateTimePickerFormat.Custom;
			this.dtpFrom.Location = new System.Drawing.Point(174, 21);
			this.dtpFrom.Name = "dtpFrom";
			this.dtpFrom.Size = new Size(81, 21);
			this.dtpFrom.TabIndex = 148;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmBookSellNotBill";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "SỔ BÁN THUÔC KHÔNG THEO ĐƠN";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmInput_Load);
			base.KeyDown += new KeyEventHandler(this.frmInput_KeyDown);
			((ISupportInitialize)this.dgvProduct).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
		}
		public frmBookSellNotBill()
		{
			this.InitializeComponent();
			this.sqlCon = this.objFunc.strConnectionString;
		}
		private void frmInput_Load(object sender, EventArgs e)
		{
			this.currWhID = this.objFunc.getWarehouse(this.userName);
			this.dgvProduct.AutoGenerateColumns = false;
			this.getInfomation();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmInput_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F7)
			{
				this.btnPrint.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.Escape)
				{
					base.Close();
				}
			}
		}
		public void getInfomation()
		{
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Pid", typeof(string));
				DataColumn column2 = new DataColumn("createDate", typeof(DateTime));
				DataColumn column3 = new DataColumn("productName", typeof(string));
				DataColumn column4 = new DataColumn("productUnit", typeof(string));
				DataColumn column5 = new DataColumn("productNumber", typeof(string));
				DataColumn column6 = new DataColumn("_DoctorDesease", typeof(string));
				DataColumn column7 = new DataColumn("Note", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				dataTable.Columns.Add(column6);
				dataTable.Columns.Add(column7);
				SqlConnection sqlConnection = new SqlConnection(this.sqlCon);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT * FROM [TabDetailBill],[TabBill] WHERE [TabBill].[CreateDate] BETWEEN @ObjDate1 AND @objDate2 AND [TabDetailBill].[billID] = [TabBill].[ID] AND [billID] IN (SELECT [ID] FROM [TabBill] WHERE [_DoctorName] = 'NONE' AND [WID] = '" + this.currWhID + "' AND TypeInput = 'OUT4') ORDER BY [TabBill].[createDate] ASC";
				SqlParameter sqlParameter = new SqlParameter("ObjDate1", SqlDbType.DateTime);
				SqlParameter sqlParameter2 = new SqlParameter("ObjDate2", SqlDbType.DateTime);
				sqlParameter.Value = DateTime.Parse(this.dtpFrom.Value.ToString().Substring(0, 10) + " 00:00:00 AM");
				sqlParameter2.Value = DateTime.Parse(this.dtpTo.Value.ToString().Substring(0, 10) + " 11:59:59 PM");
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.Parameters.Add(sqlParameter2);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Pid"].ToString(),
						sqlDataReader["createDate"].ToString(),
						sqlDataReader["productName"].ToString(),
						sqlDataReader["productUnit"].ToString(),
						sqlDataReader["productNumber"].ToString(),
						sqlDataReader["_DoctorDesease"].ToString(),
						sqlDataReader["Note"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.objTable = dataTable;
				this.dgvProduct.DataSource = this.objTable;
			}
			catch
			{
				this.objTable = null;
				this.dgvProduct.DataSource = this.objTable;
			}
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			this.getInfomation();
		}
		private void resetDataGridView()
		{
			this.objTable = null;
			this.dgvProduct.DataSource = this.objTable;
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			new frmAddSideEffects
			{
				ID = "0"
			}.ShowDialog();
		}
		private void btnUpdate_Click(object sender, EventArgs e)
		{
			frmBookSellNotBillView frmBookSellNotBillView = new frmBookSellNotBillView();
			frmBookSellNotBillPrint.objTable = this.objTable;
			frmBookSellNotBillView.ShowDialog();
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmBookSellNotBillPrint.objTable = new DataTable();
				frmBookSellNotBillPrint.objTable = this.objTable;
				ActiveReport3 activeReport = new frmBookSellNotBillPrint();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
	}
}
